package ua.maxicash.util.criteria.handlers;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Junction;
import org.hibernate.criterion.Restrictions;
import ua.maxicash.util.Filter;
import ua.maxicash.util.criteria.RestrictionsWrapper;

import java.util.List;

public class EmployerCriteriaHandler extends CriteriaHandler {

	private Filter filter;

    public EmployerCriteriaHandler() {
    }

    public EmployerCriteriaHandler(List<String> aliases) {
        super(aliases);
    }

    @Override
	public void setUp(Filter filter) {
		this.filter = filter;
	}

	@Override
	public DetachedCriteria handle(DetachedCriteria criteria, Junction junction) {

        if (!aliases.contains("employer")) {
            criteria.createAlias("employer", "employer");
            aliases.add("employer");
        }

        junction.add(RestrictionsWrapper.getCriterion(filter.getOp(),
                  "employer.email",filter.getData()));

		return criteria;
	}
}
